/**
 * 登录凭证守卫
 */
import type { Router } from 'vue-router'
import { ElMessage } from 'element-plus'
import { useAuthStore } from '@/store/modules/auth'

export function groudToken(router: Router) {
  router.beforeEach((to, form, next) => {
    const authStore = useAuthStore()
    if (authStore.Token.value) {
      next()
    }
    else {
      if (to.path === '/login') {
        next()
      }
      else {
        ElMessage.error('登录过期，请重新登录')
        next({
          path: '/login',
        })
      }
    }
  })
}
